package com.minigame.rpc.server;

import com.minigame.rpc.config.ServerConfig;
import io.netty.channel.socket.nio.NioServerSocketChannel;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class RpcServerBootStrap {

    private static Map<String,RpcServer> rpcServerMap = new ConcurrentHashMap<>();

    public static RpcServer buildRpcServer(ServerConfig serverConfig)
    {
        RpcServer rpcServer = new RpcServer();
        rpcServer.init(serverConfig);
        rpcServer.start();
        rpcServerMap.put(serverConfig.getName(),rpcServer);
        return rpcServer;
    }

    public static void stopAll()
    {
        for(RpcServer rpcServer : rpcServerMap.values())
        {
            rpcServer.stop();
        }
    }


    public static void main(String[] args)
    {
        ServerConfig serverConfig = new ServerConfig();
        serverConfig.setName("test");
        serverConfig.setPort(8080);
        buildRpcServer(serverConfig);
    }
}
